package com.huiminpay.paymentagent.message;

import com.huiminpay.paymentagent.api.conf.AliConfigParam;
import com.huiminpay.paymentagent.api.dto.PaymentResponseDTO;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class PayProducer {

    //消息Topic
    private static final String TOPIC_ORDER = "TP_PAYMENT_ORDER";   //查询消息的主题
    private static final String TOPIC_RESULT = "TP_PAYMENT_RESULT";  //结果消息的主题

//    @Autowired
    @Resource
    RocketMQTemplate rocketMQTemplate;

    //发送查询的延迟消息
    public  void payPrderNotice(PaymentResponseDTO<AliConfigParam> dto  ){
        Message<PaymentResponseDTO<AliConfigParam>> message = MessageBuilder.withPayload(dto).build();

        //延迟等级3  -->10秒后发送
        rocketMQTemplate.syncSend(TOPIC_ORDER,message,1000,3);
    }


    // 发送结果消息
    public void payResultotive(PaymentResponseDTO result){
        rocketMQTemplate.convertAndSend(TOPIC_RESULT,result);
    }

}
